package com.dalin.platform.loa.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.dalin.common.base.BaseObject;
/*****************************************************************************
 * @content: 字典表细目类信息                                                                                                                 *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-11                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="LOA_DIC_ITEM")
public class LoaDicItemEntity extends BaseObject {
    private Long itemId; // ITEM_ID,16,0
    private Long typeId; // TYPE_ID,16,0
	private String itemCode; // ITEM_CODE,8,0
    private String itemName; // ITEM_NAME,256,0
    private String parentItemCode; // PARENT_ITEM_CODE,8,0
    private Integer orderNumber; // ORDER_NUMBER,8,0
    private String remark; // REMARK,512,0
    private Date createDate; // CREATE_DATE,7,0
    private Date modifyDate; // MODIFY_DATE,7,0
    private Integer valid; // VALID,2,0

    private Set<LoaRoleEntity> loaRoleEntitys = new HashSet<LoaRoleEntity>(0);





	@Id
    @Column(name="ITEM_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "LOA_DIC_ITEM",
        allocationSize=1
    )
    public Long getItemId() {
        return itemId;
    }

    public void setItemId(Long itemId) {
        this.itemId = itemId;
    }

    @Column(name = "TYPE_ID")
    public Long getTypeId() {
		return typeId;
	}

	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}
	
    @Column(name="ITEM_CODE")
    public String getItemCode() {
        return itemCode;
    }

	public void setItemCode(String itemCode) {
        this.itemCode = itemCode;
    }

    @Column(name="ITEM_NAME")
    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    @Column(name="PARENT_ITEM_CODE")
	public String getParentItemCode() {
		return parentItemCode;
	}
    public void setParentItemCode(String parentItemCode) {
		this.parentItemCode = parentItemCode;
	}

	
    @Column(name="ORDER_NUMBER")
    public Integer getOrderNumber() {
        return orderNumber;
    }
    public void setOrderNumber(Integer orderNumber) {
        this.orderNumber = orderNumber;
    }
	
	


    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="CREATE_DATE")
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="MODIFY_DATE")
    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }
    
    @Column(name="REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	
    @Column(name="VALID")
    public Integer getValid() {
        return valid;
    }

    public void setValid(Integer valid) {
        this.valid = valid;
    }

    
    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinTable(name = "LOA_ROLE_DICTIONARY_ITEM", joinColumns = {
	        @JoinColumn(name = "ITEM_ID")
	    }, inverseJoinColumns =  {
	        @JoinColumn(name = "ROLE_ID")
	    }
    )
    public Set<LoaRoleEntity> getLoaRoleEntitys() {
		return loaRoleEntitys;
	}

	public void setLoaRoleEntitys(Set<LoaRoleEntity> loaRoleEntitys) {
		this.loaRoleEntitys = loaRoleEntitys;
	}

    @Override
    public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (itemId == null ? 0 : itemId.hashCode());
        njlrst = 31 * njlrst + (typeId == null ? 0 : typeId.hashCode());
        njlrst = 31 * njlrst + (itemCode == null ? 0 : itemCode.hashCode());
        njlrst = 31 * njlrst + (itemName == null ? 0 : itemName.hashCode());
        njlrst = 31 * njlrst + (parentItemCode == null ? 0 : parentItemCode.hashCode());
        njlrst = 31 * njlrst + (orderNumber == null ? 0 : orderNumber.hashCode());
        njlrst = 31 * njlrst + (remark == null ? 0 : remark.hashCode());
        njlrst = 31 * njlrst + (createDate == null ? 0 : createDate.hashCode());
        njlrst = 31 * njlrst + (modifyDate == null ? 0 : modifyDate.hashCode());
        njlrst = 31 * njlrst + (valid == null ? 0 : valid.hashCode());
        njlrst = 31 * njlrst + (loaRoleEntitys == null ? 0 : loaRoleEntitys.hashCode());
        return njlrst;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof LoaDicItemEntity)) return false;
        final LoaDicItemEntity other = (LoaDicItemEntity) o;
        if (itemId == null) {
            if (other.itemId != null) return false;
        } else if (!itemId.equals(other.itemId)) {
            return false;
        }
        if (typeId == null) {
            if (other.typeId != null) return false;
        } else if (!typeId.equals(other.typeId)) {
            return false;
        }
        if (itemCode == null) {
            if (other.itemCode != null) return false;
        } else if (!itemCode.equals(other.itemCode)) {
            return false;
        }
        if (itemName == null) {
            if (other.itemName != null) return false;
        } else if (!itemName.equals(other.itemName)) {
            return false;
        }
        if (parentItemCode == null) {
            if (other.parentItemCode != null) return false;
        } else if (!parentItemCode.equals(other.parentItemCode)) {
            return false;
        }
        if (orderNumber == null) {
            if (other.orderNumber != null) return false;
        } else if (!orderNumber.equals(other.orderNumber)) {
            return false;
        }
        if (remark == null) {
            if (other.remark != null) return false;
        } else if (!remark.equals(other.remark)) {
            return false;
        }
        if (createDate == null) {
            if (other.createDate != null) return false;
        } else if (!createDate.equals(other.createDate)) {
            return false;
        }
        if (modifyDate == null) {
            if (other.modifyDate != null) return false;
        } else if (!modifyDate.equals(other.modifyDate)) {
            return false;
        }
        if (valid == null) {
            if (other.valid != null) return false;
        } else if (!valid.equals(other.valid)) {
            return false;
        }
        if (loaRoleEntitys == null) {
            if (other.loaRoleEntitys != null) return false;
        } else if (!loaRoleEntitys.equals(other.loaRoleEntitys)) {
            return false;
        }
        return true;
    }
}
